home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / atari / c / stngpasm / pure_c / include / sting / transprt.sh < prev   
Encoding:
Text File  |  1997-08-18  |  14.3 KB  |  406 lines

  1. ;----------------------------------------------------------------------------
  2. ; File name:    TRANSPRT.SH            Revision date:    1997.08.01
  3. ; Authors:    Peter Rottengatter&        Creation date:    1997.03.26
  4. ;        Ronald Andersson        Version:    1.00
  5. ;----------------------------------------------------------------------------
  6. ; Purpose:    High level StinG client support
  7. ;        Header file included in assembly
  8. ;----------------------------------------------------------------------------
  9. ;Required header declarations:
  10. ;
  11. ;    .include    "uran\STRUCT.SH"
  12. ;    .include    "sting\TRANSPORT.SH"
  13. ;
  14. ;copy the above to the header of your program and 'uncomment' the includes
  15. ;----------------------------------------------------------------------------
  16. ;
  17. ;TRANSPORT_DRIVER    "TRANSPORT_TCPIP"
  18. ;TCP_DRIVER_VERSION    "01.00"
  19. ;
  20. ;----------------------------------------------------------------------------
  21. ;        Driver access structure / functions
  22. ;
  23. ;MAGIC    "STiKmagic"            ; Magic for DRV_LIST.magic
  24. ;CJTAG    "STiK"
  25. ;
  26.     struct    DRV_HDR            ; Header part of TPL structure
  27.     char_p    DRV_HDR_module        ; Specific string that can be searched for
  28.     char_p    DRV_HDR_author        ; Any string
  29.     char_p    DRV_HDR_version        ; Format `00.00' Version:Revision
  30.     d_end    DRV_HDR
  31. ;
  32.     struct    DRV_LIST
  33.     d_s    DRV_LIST_magic,10    ; Magic string, def'd as "STiKmagic"
  34.     func_p    DRV_LIST_get_dftab    ;DRV_HDR * cdecl (*get_dftab) (char *);
  35.     func_p    DRV_LIST_ETM_exec    ;int16    cdecl (*ETM_exec) (char *);    ; Execute a STinG module
  36.     void_p    DRV_LIST_cfg        ; Config structure
  37.     void_p    DRV_LIST_sting_basepage    ; STinG basepage address
  38.     d_end    DRV_LIST
  39. ;
  40.     .import    drivers            ;extern DRV_LIST *drivers;
  41. ;
  42.     .macro    get_dftab    ch_p
  43.     move.l    ch_p,-(sp)
  44.     move.l    drivers,a0
  45.     move.l    DRV_LIST_get_dftab(a0),a0
  46.     jsr    (a0)
  47.     addq    #4,sp
  48.     .endm
  49. ;
  50.     .macro    ETM_exec
  51.     move.l    ch_p,-(sp)
  52.     move.l    drivers,a0
  53.     move.l    DRV_LIST_ETM_exec(a0),a0
  54.     jsr    (a0)
  55.     addq    #4,sp
  56.     .endm
  57. ;
  58. ;----------------------------------------------------------------------------
  59. ;        TCP connection states
  60. ;
  61. TCLOSED        equ    0    ; No connection.    Null, void, absent, ...
  62. TLISTEN        equ    1    ; Wait for remote request
  63. TSYN_SENT    equ    2    ; Connect request sent, await matching request
  64. TSYN_RECV    equ    3    ; Wait for connection ack
  65. TESTABLISH    equ    4    ; Connection established, handshake completed
  66. TFIN_WAIT1    equ    5    ; Await termination request or ack
  67. TFIN_WAIT2    equ    6    ; Await termination request
  68. TCLOSE_WAIT    equ    7    ; Await termination request from local user
  69. TCLOSING    equ    8    ; Await termination ack from remote TCP
  70. TLAST_ACK    equ    9    ; Await ack of terminate request sent
  71. TTIME_WAIT    equ    10    ; Delay, ensures remote has received term' ack
  72. ;
  73. ;----------------------------------------------------------------------------
  74. ;        Error return values
  75. ;
  76. E_NORMAL    equ    0    ; No error occured ...
  77. E_OBUFFULL    equ    -1    ; Output buffer is full
  78. E_NODATA    equ    -2    ; No data available
  79. E_EOF        equ    -3    ; EOF from remote
  80. E_RRESET    equ    -4    ; Reset received from remote
  81. E_UA        equ    -5    ; Unacceptable packet received, reset
  82. E_NOMEM        equ    -6    ; Something failed due to lack of memory
  83. E_REFUSE    equ    -7    ; Connection refused by remote
  84. E_BADSYN    equ    -8    ; A SYN was received in the window
  85. E_BADHANDLE    equ    -9    ; Bad connection handle used.
  86. E_LISTEN    equ    -10    ; The connection is in LISTEN state
  87. E_NOCCB        equ    -11    ; No free CCB's available
  88. E_NOCONNECTION    equ    -12    ; No connection matches this packet (TCP)
  89. E_CONNECTFAIL    equ    -13    ; Failure to connect to remote port (TCP)
  90. E_BADCLOSE    equ    -14    ; Invalid TCP_close() requested
  91. E_USERTIMEOUT    equ    -15    ; A user function timed out
  92. E_CNTIMEOUT    equ    -16    ; A connection timed out
  93. E_CANTRESOLVE    equ    -17    ; Can't resolve the hostname
  94. E_BADDNAME    equ    -18    ; Domain name or dotted dec. bad format
  95. E_LOSTCARRIER    equ    -19    ; The modem disconnected
  96. E_NOHOSTNAME    equ    -20    ; Hostname does not exist
  97. E_DNSWORKLIMIT    equ    -21    ; Resolver Work limit reached
  98. E_NONAMESERVER    equ    -22    ; No nameservers could be found for query
  99. E_DNSBADFORMAT    equ    -23    ; Bad format of DS query
  100. E_UNREACHABLE    equ    -24    ; Destination unreachable
  101. E_DNSNOADDR    equ    -25    ; No address records exist for host
  102. E_NOROUTINE    equ    -26    ; Routine unavailable
  103. E_LOCKED    equ    -27    ; Locked by another application
  104. E_FRAGMENT    equ    -28    ; Error during fragmentation
  105. E_TTLEXCEED    equ    -29    ; Time To Live of an IP packet exceeded
  106. E_PARAMETER    equ    -30    ; Problem with a parameter
  107. E_BIGBUF    equ    -31    ; Input buffer is too small for data
  108. E_LASTERROR    equ    31    ; ABS of last error code in this list
  109. ;
  110. ;----------------------------------------------------------------------------
  111. ;        IP packet header.
  112. ;
  113. struct    IPHD
  114.     d_field    IPHD_verlen_f,8            ;bitfield
  115.     d_bits    IPHD_f_version,    4    ; IP Version
  116.     d_bits    IPHD_f_hd_len,    4    ; Internet Header Length/4
  117.     uint8    IPHD_tos        ; Type of Service
  118.     uint16    IPHD_length        ; Total of all header, options and data
  119.     uint16    IPHD_ident        ; Identification for fragmentation
  120.     d_field    IPHD_frag_f,16            ;bitfield
  121.     d_bits    IPHD_f_reserved,1    ; Reserved : Must be zero
  122.     d_bits    IPHD_f_dont_frg,1    ; Don't fragment flag
  123.     d_bits    IPHD_f_more_frg,1    ; More fragments flag
  124.     d_bits    IPHD_f_frag_ofst,13    ; Fragment offset
  125.     uint8    IPHD_ttl        ; Time to live
  126.     uint8    IPHD_protocol        ; Protocol
  127.     uint16    IPHD_hdr_chksum        ; Header checksum
  128.     uint32    IPHD_ip_src        ; Source IP address
  129.     uint32    IPHD_ip_dest        ; Destination IP address
  130. d_end    IPHD
  131. ;
  132. ;----------------------------------------------------------------------------
  133. ;        Internal IP packet representation.
  134. ;
  135. struct    IPDG
  136.     d_s        IPDG_hdr,sizeof_IPHD    ; Header of IP packet
  137.     void_p        IPDG_options        ; Options data block
  138.     int16        IPDG_opt_length        ; Length of options data block
  139.     void_p        IPDG_pkt_data        ; IP packet data block
  140.     int16        IPDG_pkt_length        ; Length of IP packet data block
  141.     uint32        IPDG_timeout        ; Timeout of packet life
  142.     uint32        IPDG_ip_gateway        ; Gateway for forwarding this packet
  143.     void_p        IPDG_recvd        ; Receiving port
  144.     struct_p    IPDG_next        ; Next IP packet in IP packet queue
  145. d_end    IPDG
  146. ;
  147. ;----------------------------------------------------------------------------
  148. ;        Input queue structures
  149. ;
  150. struct    NDB            ; Network Data Block.    For data delivery
  151.     char_p        NDB_ptr        ; Pointer to base of block. (For KRfree)
  152.     char_p        NDB_ndata    ; Pointer to next data to deliver
  153.     uint16        NDB_len        ; Length of remaining data
  154.     struct_p    NDB_next    ; Next NDB in chain or NULL
  155. d_end    NDB
  156. ;
  157. ;----------------------------------------------------------------------------
  158. ;        Connection information block
  159. ;
  160. struct    CIB        ; Connection Information Block
  161.     uint16    CIB_protocol    ; TCP or UDP or ... 0 means CIB is not in use
  162.     uint16    CIB_lport    ; TCP local    port    (ie: local machine)
  163.     uint16    CIB_rport    ; TCP remote port    (ie: remote machine)
  164.     uint32    CIB_rhost    ; TCP remote IP addr    (ie: remote machine)
  165.     uint32    CIB_lhost    ; TCP local    IP addr    (ie: local machine)
  166.     uint16    CIB_status    ; Net status. 0 means normal
  167. d_end    CIB
  168. ;
  169. ;----------------------------------------------------------------------------
  170. ;    Values for protocol field
  171. ;
  172. P_ICMP    equ    1    ; IP assigned number for ICMP
  173. P_TCP    equ    6    ; IP assigned number for TCP
  174. P_UDP    equ    17    ; IP assigned number for UDP
  175. ;
  176. ;----------------------------------------------------------------------------
  177. ;        Handler flag values.
  178. ;
  179. HNDLR_SET    equ    0        ; Set new handler if space        */
  180. HNDLR_FORCE    equ    1        ; Force new handler to be set        */
  181. HNDLR_REMOVE    equ    2        ; Remove handler entry            */
  182. HNDLR_QUERY    equ    3        ; Inquire about handler entry        */
  183. ;
  184. ;----------------------------------------------------------------------------
  185. ;        Transport structure / functions
  186. ;
  187. struct TPL
  188.     char_p    TPL_module        ; Specific string that can be searched for
  189.     char_p    TPL_author        ; Any string
  190.     char_p    TPL_version        ; Format `00.00' Version:Revision
  191. ;
  192.     func_p    TPL_KRmalloc        ;void *    cdecl    (* KRmalloc) (int32);
  193.     func_p    TPL_KRfree        ;void    cdecl    (* KRfree) (void *);
  194.     func_p    TPL_KRgetfree        ;int32    cdecl    (* KRgetfree) (int16);
  195.     func_p    TPL_KRrealloc        ;void *    cdecl    (* KRrealloc) (void *, int32);
  196. ;
  197.     func_p    TPL_get_err_text    ;char *    cdecl    (* get_err_text) (int16);
  198.     func_p    TPL_getvstr        ;char *    cdecl    (* getvstr) (char *);
  199. ;
  200.     func_p    TPL_carrier_detect    ;int16    cdecl    (* carrier_detect) (void);
  201. ;
  202.     func_p    TPL_TCP_open        ;int16    cdecl    (* TCP_open) (uint32, int16, int16, uint16);
  203.     func_p    TPL_TCP_close        ;int16    cdecl    (* TCP_close) (int16, int16);
  204.     func_p    TPL_TCP_send        ;int16    cdecl    (* TCP_send) (int16, void *, int16);
  205.     func_p    TPL_TCP_wait_state    ;int16    cdecl    (* TCP_wait_state) (int16, int16, int16);
  206.     func_p    TPL_TCP_ack_wait    ;int16    cdecl    (* TCP_ack_wait) (int16, int16);
  207. ;
  208.     func_p    TPL_UDP_open        ;int16    cdecl    (* UDP_open) (uint32, int16);
  209.     func_p    TPL_UDP_close        ;int16    cdecl    (* UDP_close) (int16);
  210.     func_p    TPL_UDP_send        ;int16    cdecl    (* UDP_send) (int16, void *, int16);
  211. ;
  212.     func_p    TPL_CNkick        ;int16    cdecl    (* CNkick) (int16);
  213.     func_p    TPL_CNbyte_count    ;int16    cdecl    (* CNbyte_count) (int16);
  214.     func_p    TPL_CNget_char        ;int16    cdecl    (* CNget_char) (int16);
  215.     func_p    TPL_CNget_NDB        ;NDB *    cdecl    (* CNget_NDB) (int16);
  216.     func_p    TPL_CNget_block        ;int16    cdecl    (* CNget_block) (int16, void *, int16);
  217. ;
  218.     func_p    TPL_housekeep        ;void    cdecl    (* housekeep) (void);
  219.     func_p    TPL_resolve        ;int16    cdecl    (* resolve) (char *, char **, uint32 *, int16);
  220.     func_p    TPL_ser_disable        ;void    cdecl    (* ser_disable) (void);
  221.     func_p    TPL_ser_enable        ;void    cdecl    (* ser_enable) (void);
  222.     func_p    TPL_set_flag        ;int16    cdecl    (* set_flag) (int16);
  223.     func_p    TPL_clear_flag        ;void    cdecl    (* clear_flag) (int16);
  224.     func_p    TPL_CNgetinfo        ;CIB *    cdecl    (* CNgetinfo) (int16);
  225.     func_p    TPL_on_port        ;int16    cdecl    (* on_port) (char *);
  226.     func_p    TPL_off_port        ;void    cdecl    (* off_port) (char *);
  227.     func_p    TPL_setvstr        ;int16    cdecl    (* setvstr) (char *, char *);
  228.     func_p    TPL_query_port        ;int16    cdecl    (* query_port) (char *);
  229.     func_p    TPL_CNgets        ;int16    cdecl    (* CNgets) (int16, char *, int16, char);
  230.     func_p    TPL_ICMP_send        ;int16    cdecl    (* ICMP_send) (uint32, uint8, uint8, void *, uint16);
  231.     func_p    TPL_ICMP_handler    ;int16    cdecl    (* ICMP_handler) (int16 cdecl (*) (IP_DGRAM *), int16);
  232.     func_p    TPL_ICMP_discard    ;void    cdecl    (* ICMP_discard) (IP_DGRAM *);
  233. d_end    TPL
  234. ;
  235.     .import    tpl    ;extern TPL *tpl;
  236. ;
  237. ;----------------------------------------------------------------------------
  238. ;    Definitions of transport function macros for direct use
  239. ;----------------------------------------------------------------------------
  240. ;    Submacros are used to make the interface flexible and powerful
  241. ;
  242. ;sub_tpl.mode    is used to implement all TPL functions, and uses submacro
  243. ;        sub_sub_tpl as well as some of URAn_SYS.SH.  It gives argument
  244. ;        count check for all macros, and allows indirection of pointers.
  245. ;----------------------------------------------------------------------------
  246. ;
  247. .MACRO    sub_tpl.mode    function,arg_count,arg_flags,arg1,arg2,arg3,arg4,arg5
  248.     CDECL_args.mode    arg_flags,arg1,arg2,arg3,arg4,arg5
  249.     sub_sub_tpl    TPL_&function
  250.     CDECL_cleanargs    function,arg_count
  251. .ENDM    sub_tpl
  252. ;
  253. ;-------------------------------------
  254. ;
  255. .MACRO    sub_sub_tpl    tpl_function
  256.     move.l    tpl,a0
  257.     move.l    tpl_function(a0),a0
  258.     jsr    (a0)
  259. .ENDM    sub_sub_tpl
  260. ;
  261. ;----------------------------------------------------------------------------
  262. ;
  263. .MACRO    KRmalloc    size
  264.     sub_tpl    KRmalloc,1,2,size
  265. .ENDM    KRmalloc
  266. ;
  267. .MACRO    KRfree.mode    block_p
  268.     sub_tpl.mode    KRfree,1,3,block_p
  269. .ENDM    KRfree
  270. ;
  271. .MACRO    KRgetfree    mode_f
  272.     sub_tpl    KRgetfree,1,1,mode_f
  273. .ENDM    KRgetfree
  274. ;
  275. .MACRO    KRrealloc.mode    block_p,size
  276.     sub_tpl.mode    KRrealloc,2,$B,block_p,size
  277. .ENDM    KRrealloc
  278. ;
  279. .MACRO    get_err_text    err_code
  280.     sub_tpl    get_err_text,1,1,err_code
  281. .ENDM    get_err_text
  282. ;
  283. .MACRO    getvstr.mode    varname_p
  284.     sub_tpl.mode    getvstr,1,3,varname_p
  285. .ENDM    getvstr
  286. ;
  287. .MACRO    carrier_detect
  288.     sub_tpl    carrier_detect,0,0
  289. .ENDM    carrier_detect
  290. ;
  291. .MACRO    TCP_open    remote_IP,protoport,tos,obuff_size
  292.     sub_tpl    TCP_open,4,$56,remote_IP,protoport,tos,obuff_size
  293. .ENDM    TCP_open
  294. ;
  295. .MACRO    TCP_close    cn_handle,timeout_sec
  296.     sub_tpl    TCP_close,2,$5,cn_handle,timeout_sec
  297. .ENDM    TCP_close
  298. ;
  299. .MACRO    TCP_send.mode    cn_handle,data_p,datalen
  300.     sub_tpl.mode    TCP_send,3,$1D,cn_handle,data_p,datalen
  301. .ENDM    TCP_send
  302. ;
  303. .MACRO    TCP_wait_state    cn_handle,state,timeout_sec
  304.     sub_tpl    TCP_wait_state,3,$15,cn_handle,state,timeout_sec
  305. .ENDM    TCP_wait_state
  306. ;
  307. .MACRO    TCP_ack_wait    cn_handle,timeout_ms
  308.     sub_tpl    TCP_ack_wait,2,$5,cn_handle,timeout_ms
  309. .ENDM    TCP_ack_wait
  310. ;
  311. .MACRO    UDP_open    remote_IP,remote_port
  312.     sub_tpl    UDP_open,2,$6,remote_IP,remote_port
  313. .ENDM    UDP_open
  314. ;
  315. .MACRO    UDP_close    cn_handle
  316.     sub_tpl    UDP_close,1,1,cn_handle
  317. .ENDM    UDP_close
  318. ;
  319. .MACRO    UDP_send.mode    cn_handle,data_p,datalen
  320.     sub_tpl.mode    UDP_send,3,$1D,cn_handle,data_p,datalen
  321. .ENDM    UDP_send
  322. ;
  323. .MACRO    CNkick    cn_handle
  324.     sub_tpl    CNkick,1,1,cn_handle
  325. .ENDM    CNkick
  326. ;
  327. .MACRO    CNbyte_count    cn_handle
  328.     sub_tpl    CNbyte_count,1,1,cn_handle
  329. .ENDM    CNbyte_count
  330. ;
  331. .MACRO    CNget_char    cn_handle
  332.     sub_tpl    CNget_char,1,1,cn_handle
  333. .ENDM    CNget_char
  334. ;
  335. .MACRO    CNget_NDB    cn_handle
  336.     sub_tpl    CNget_NDB,1,1,cn_handle
  337. .ENDM    CNget_NDB
  338. ;
  339. .MACRO    CNget_block.mode    cn_handle,buff_p,bufflen
  340.     sub_tpl.mode    CNget_block,3,$1D,cn_handle,buff_p,bufflen
  341. .ENDM    CNget_block
  342. ;
  343. .MACRO    CNgetinfo    cn_handle
  344.     sub_tpl    CNgetinfo,1,1,cn_handle
  345. .ENDM    CNgetinfo
  346. ;
  347. .MACRO    CNgets.mode    cn_handle,buff_p,bufflen,delim_ch
  348.     sub_tpl.mode    CNgets,4,$1D,cn_handle,buff_p,bufflen,delim_ch
  349. .ENDM    CNgets
  350. ;
  351. .MACRO    housekeep
  352.     sub_tpl    housekeep,0,0
  353. .ENDM    housekeep
  354. ;
  355. .MACRO    resolve.mode    search_p,real_p_p,IP_list_p,list_len
  356.     sub_tpl.mode    resolve,4,$7F,search_p,real_p_p,IP_list_p,list_len
  357. .ENDM    resolve
  358. ;
  359. .MACRO    ser_disable
  360.     sub_tpl    ser_disable,0,0
  361. .ENDM    ser_disable
  362. ;
  363. .MACRO    ser_enable
  364.     sub_tpl    ser_enable,0,0
  365. .ENDM    ser_enable
  366. ;
  367. .MACRO    set_flag    flag_index
  368.     sub_tpl    set_flag,1,1,flag_index
  369. .ENDM    set_flag
  370. ;
  371. .MACRO    clear_flag    flag_index
  372.     sub_tpl    clear_flag,1,1,flag_index
  373. .ENDM    clear_flag
  374. ;
  375. .MACRO    on_port.mode    char_p
  376.     sub_tpl.mode    on_port,1,3,char_p
  377. .ENDM    on_port
  378. ;
  379. .MACRO    off_port.mode    char_p
  380.     sub_tpl.mode    off_port,1,3,char_p
  381. .ENDM    off_port
  382. ;
  383. .MACRO    setvstr.mode    varname_p,valuestring_p
  384.     sub_tpl.mode    setvstr,2,$F,varname_p,valuestring_p
  385. .ENDM    setvstr
  386. ;
  387. .MACRO    query_port.mode    char_p
  388.     sub_tpl.mode    query_port,1,3,char_p
  389. .ENDM    query_port
  390. ;
  391. .MACRO    ICMP_send.mode    remote_IP,type,code,data_p,datalen
  392.     sub_tpl.mode    ICMP_send,5,$182,remote_IP,type,code,data_p,datalen
  393. .ENDM    ICMP_send
  394. ;
  395. .MACRO    ICMP_handler.mode    handler_p,install_code
  396.     sub_tpl.mode    ICMP_handler,2,7,handler_p,install_code
  397. .ENDM    ICMP_handler
  398. ;
  399. .MACRO    ICMP_discard.mode    dgram_p
  400.     sub_tpl.mode    ICMP_discard,1,3,dgram_p
  401. .ENDM    ICMP_discard
  402. ;
  403. ;----------------------------------------------------------------------------
  404. ; End of file:    TRANSPRT.SH
  405. ;----------------------------------------------------------------------------
  406.